(function(){

//Start

//时间段表
const TIME_TABLE = [
  ['08:00', '08:29'], ['08:30', '08:59'], 
  ['09:00', '09:29'], ['09:30', '09:59'],
  ['10:00', '10:29'], ['10:30', '10:59'],
  ['11:00', '11:29'], ['11:30', '11:59'],
  ['14:30', '14:59'],
  ['15:00', '15:29'], ['15:30', '15:59'],
  ['16:00', '16:29'], ['16:30', '16:59']
];
//每日毫秒数
const MS_A_DAY = 24*60*60*1000;
  
//把一个日期转为YYYY-MM-DD格式
function makeDateString(_date){

  let result = _date.getFullYear()+'-';
  result += (_date.getMonth()+1+100+'').slice(1)+'-';
  result += (_date.getDate()+100+'').slice(1);

  return result;

}
  
//尝试邓来明的一个请求
function tryDenglaiming(reg_dat, sta_tm, end_tm){
  
  let tm_flg = 1;
  if(sta_tm.slice(0,2)*1 > 12) tm_flg = 2;
  let url = `https://www.guahao.gov.cn/reg_confirm.xhtml?HIS_CD=1001&DEP_ID=25&DOC_ID=2045&DOC_NM=&REG_DAT=${reg_dat}&TM_FLG=${tm_flg}&REG_FEE=0.00&TRE_FEE=10.00&BBREG_FEE=0.00&BBTRE_FEE=13.00&STA_TM=${sta_tm}&END_TM=${end_tm}`;
  
  //获取请求,可以成功挂号则显示在控制台
  $.ajax({
    'url': url,
    'success':(result,status,xhr)=>{
      /*
      if(result.indexOf('PTS39003系统错误') == -1 )
        console.log('可以挂号:', reg_dat, sta_tm);
      else
        console.log('不可以挂号:', reg_dat, sta_tm);
      */
      if(result.indexOf('邓来明') > -1 )
        console.log('可以挂号:', reg_dat, sta_tm);
      //else
        //console.log('不可以挂号:', reg_dat, sta_tm);
    }
  });
  return url

}  

//尝试邓来明一日
function tryDenglaimingOneDay(reg_dat){

  for(let i=0;i < TIME_TABLE.length;i++){
    let sta_tm = TIME_TABLE[i][0];
    let end_tm = TIME_TABLE[i][1];
    tryDenglaiming(reg_dat, sta_tm, end_tm);
  }
  
}
  
//尝试邓来明的从今天开始的第m日到之后的n日(m最小为1,n一般是14)
function tryDenglaimingNDays(m, n){
 
  let todayMs = Date.parse(new Date());
  for(let i = 0;i < n;i++){
    let _date = new Date(todayMs+MS_A_DAY*(m+i));
    if(_date.getDay() < 6){
      let reg_dat = makeDateString(_date);
      tryDenglaimingOneDay(reg_dat); 
    }
  }
  
}
  
//主代码
//return tryDenglaimingOneDay('2021-06-24');
return tryDenglaimingNDays(7, 7);
  
//End
  
})();


/*
https://www.guahao.gov.cn/reg_confirm.xhtml?HIS_CD=1001&DEP_ID=25&DOC_ID=2045&DOC_NM=&REG_DAT=2021-06-21&TM_FLG=2&REG_FEE=0.00&TRE_FEE=10.00&BBREG_FEE=0.00&BBTRE_FEE=13.00&STA_TM=15:00&END_TM=15:29
*/
/*
Exception: ReferenceError: date is not defined
tryDenglaimingNDays@Scratchpad/1:72:9
@Scratchpad/1:83:8
@Scratchpad/1:1:2
*/